import { AfterViewInit, Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { MenuController } from '@ionic/angular';
import { TranslateService } from '@ngx-translate/core';
import { CommonService } from 'src/app/services/common.service';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.scss'],
})
export class HomeComponent implements OnInit, AfterViewInit {

  userInfo: any = {};

  constructor(
    private mc: MenuController,
    private router: Router,
    private i18l: TranslateService,
    private commonservice:CommonService,
  ) { 
    this.userInfo.name = '糖果仁先生'
    this.userInfo.avatar = '../assets/images/df-avatar.jpg'
    this.userInfo.remark = '要有梦想 要有梦想 要有梦想 要有梦想 要有梦想'
    this.userInfo.lv = '9'
  }

  ngOnInit() {

  }
  ngAfterViewInit(): void {
  }



  onTabChange(val) {
    switch (val.detail.value) {
      case '1':
        this.router.navigateByUrl('/home/my')
        break;
      case '2':
        this.router.navigateByUrl('/home/recommend')
        break;
      case '3':
        this.router.navigateByUrl('/home/about')
        break;
      default:
        this.router.navigateByUrl('/home/recommend')
        break;
    }


  }


  onChangeLang() {
    if (this.i18l.store.currentLang.includes('en_US')) {
      this.i18l.use('en_US')
    } else {
      this.i18l.use('zh_CN')
    }
  }

  onOpenMenu() {
    this.mc.open();
  }

  onUpTheme(ev) {
    console.log(ev.detail.checked);
    if (ev.detail.checked) {
      this.commonservice.theme = 'dark-theme'
    } else {
      this.commonservice.theme = 'light-theme'
    }
  }




}
